<template>
  <view>
    <view class="u-page">
      <view class="con">
        <!-- 人员选择页 -->
        <u-search
          placeholder="请输入人员关键词"
          v-model="keyword"
          shape="square"
          bgColor="#fff"
        ></u-search>
        <!-- 领导的工地任务 -->
        <view class="ryxz"  v-if='userInfo.type=="领导"&&ssgdId'>
          <u-subsection
            :list="list"
            :current="current"
            @change="sectionChange"
            fontSize="15"
          ></u-subsection>
        </view>
        <!-- 科员的工地任务 -->
        <view class="ryxz"  v-if='userInfo.type=="科员"&&ssgdId'>
          <u-subsection
            :list="list1"
            :current="current"
            @change="sectionChange"
            fontSize="15"
          ></u-subsection>
        </view>
        <!-- 公用任务 -->
        <view class="ryxz"  v-if='!ssgdId&&gdName!=="其他"'>
          <u-subsection
            :list="list2"
            :current="current"
            @change="sectionChange"
            fontSize="15"
          ></u-subsection>
        </view>
        <!-- 公用任务 -->
        <view class="ryxz"  v-if='!ssgdId&&gdName=="其他"'>
          <view class="jgry">
            建管员工
          </view>
        </view>
        <view>
          <u--text class="mb-10" :text="gdName"></u--text>
          <u-checkbox-group 
            v-model="checkboxValue1"
            placement="column"
            @change="checkboxChange"
          >
            <u-checkbox
              :customStyle="{ marginBottom: '8px' }"
              v-for="(item, index) in checkboxList1"
              :key="index"
              :label="item.name"
              :name="item.id"
            >
            </u-checkbox>
          </u-checkbox-group>
        </view>
        <view>
          <u-button
            color="#5ea3f1"
            size="small"
            text="完成"
            @click="handleSel"
          ></u-button>
        </view>
      </view>
    </view>
  </view>
</template>
<script>
import { mapState, mapMutations } from "vuex";
import sceneMixins from "@/utils/sceneMixins";
import mytabbar from "@/components/tabbar/index.vue";
export default {
  options: { styleIsolation: "shared" },
  components: { mytabbar: mytabbar },
  mixins: [sceneMixins],
  computed: {
    ...mapState(["userInfo", "openId", "token", "characterType"]),
  },
  data() {
    return {
      keyword: "",
      list: ["科员", "参建方","建管员工"],//领导的
      list1: ["参建方","建管员工"],//科员的
      list2: ["公用","建管员工"],//公用的

      // 或者如下，也可以配置keyName参数修改对象键名
      // list: [{name: '未付款'}, {name: '待评价'}, {name: '已付款'}],
      current: 1,
      gdName: "",
      datas: "",
      ssgdId:"",
      checkboxValue1: [],
      // 基本案列数据
      checkboxList1: [
        {
          name: "王林",
          disabled: false,
          
        },
        {
          name: "张一湳",
          disabled: false,
        },
        {
          name: "董大成",
          disabled: false,
        },
      ],
    };
  },

  methods: {
    ...mapMutations(["changeTab", "changeCharacterType"]),
    sectionChange(index) {
      this.current = index;
      this.getRys()
    },
    checkboxChange(n) {
      var vm = this;
      vm.datas = n.toString();
    },
    handleSel() {
      var vm = this;
      var users = vm.checkboxList1.filter(n => vm.datas.includes(n.id));
      var userNames = users.map(n => n.name)
      
      var type=''
            if(this.userInfo.type=="领导"&&this.ssgdId){
              if(this.current==0){
                type='ky'
              }else if(this.current==1){
                type='cjf'
              }else{
                type='jgyg'
              }
            }
            if(this.userInfo.type=="科员"&&this.ssgdId){
            if(this.current==0){
                type='cjf'
              }else{
                type='jgyg'
              }
            }
            if(!this.ssgdId&&this.gdName!=="其他"){
              if(this.current==0){
                type='gy'
              }else{
                type='jgyg'
              }
            }
            if(this.gdName=="其他"){
              type='jgyg'
              
            }

              //   console.log("🚀 ~ file: list.vue:158 ~ handleSel ~ this.ssgdId:", this.ssgdId)
              // console.log("🚀 ~ file: list.vue:163 ~ handleSel ~ type:", type)
      uni.$emit("query", { datas: vm.datas, users, userNames,type });
      uni.navigateBack({
        delta: 1, 
      });
    },
    getRys() {
      var vm = this;
            var type=''
            if(this.userInfo.type=="领导"&&this.ssgdId){
              if(this.current==0){
                type='ky'
              }else if(this.current==1){
                type='cjf'
              }else{
                type='jgyg'
              }
            }
            if(this.userInfo.type=="科员"&&this.ssgdId){
            if(this.current==0){
                type='cjf'
              }else{
                type='jgyg'
              }
            }
            if(!this.ssgdId&&this.gdName!=="其他"){
              if(this.current==0){
                type='gy'
              }else{
                type='jgyg'
              }
            }
            if(this.gdName=="其他"){
                type='jgyg'
              
            }
      if(vm.ssgdId){
        vm.getAndLoad(
          "获取指派人员数据",
          vm.WX_ASSETS +
            "/xcx/task/selectRy.jsp?entityId=" +
            vm.ssgdId +
            "&type=" +
            type,
          function (res) {
            vm.checkboxList1 = res.data;
          }
        );
      }else{
                vm.getAndLoad(
          "获取公用管理任务人员数据",
          vm.WX_ASSETS +
            "/xcx/task/api/selectRy.jsp?type=" +
            type,
          function (res) {
            vm.checkboxList1 = res.data;
          }
        );
      }
    },
  },
  onShow() {
    var vm = this;
  },
  onLoad(params) {
    if (params.gdName) {
      this.ssgdId=params.entityId
      this.gdName = params.gdName;
    }

      // console.log("🚀 ~ file: list.vue:206 ~ onLoad ~ params.entityId:", params.entityId)
      // console.log("🚀 ~ file: list.vue:208 ~ onLoad ~ params.gdName:", params.gdName)
      this.getRys();
  },
};
</script>

<style lang="scss" scoped>
.u-page {
  height: 100vh;
  overflow: hidden;
  background: #f3f5f7;
}
.con {
  width: 90vw;
  margin: 10rpx auto;
  .ryxz {
    width: 100%;
    margin: 10rpx auto;
    .jgry{
      width: 100%;
      margin: 0 auto;
      text-align: center;
      background-color: #fff;
      color:#5ea3f1;
    }
  }
  .mb-10 {
    margin-bottom: 10rpx;
  }
}
</style>
